com.cete.dynamicpdf
Class EmbeddedFile



Example: The following example will place the embedded files into a document.

import java.io.*;
import java.util.Date;
import com.cete.dynamicpdf.*;
import com.cete.dynamicpdf.pageelements.*;
 
public class MyClass{
       public static void main(String args[]){
 
           try {
            // Create a PDF Document
            Document document = new Document();
            
            // FileStreams used for creating the instance of EmbeddedFile
            FileInputStream fileStream1 = new FileInputStream("[PhysicalPath]/DocumentA.pdf");
            FileInputStream fileStream2 = new FileInputStream("[PhysicalPath]/DocumentB.pdf");
            
            // byte array of the file by reading the file.
            byte[] filebyte = new byte[fileStream2.available()];
            fileStream2.read(filebyte, 0, filebyte.length );
            
            // Created 3 instances of EmbeddedFile using all the available constructors.
            EmbeddedFile embeddedFile1 = new EmbeddedFile("[PhysicalPath]/DocumentC.pdf");
            EmbeddedFile embeddedFile2 = new EmbeddedFile( fileStream1, "DocumentA.pdf", new Date() );
            EmbeddedFile embeddedFile3 = new EmbeddedFile( filebyte, "DocumentB.pdf", new Date() );
            
            // Added the embeddedFiles to the EmbeddedFileList of the document class.
            document.getEmbeddedFiles().add( embeddedFile1 );
            document.getEmbeddedFiles().add( embeddedFile2 );
            document.getEmbeddedFiles().add( embeddedFile3 );
            
            // Set the PageMode to the ShowAttachments
            document.setInitialPageMode(PageMode.SHOW_ATTACHMENTS);
            
            // Create a Page and add it to the document
            Page page = new Page();
            Label label = new Label("My Label 2 ",10,10,200,20,Font.getHelvetica(),14);
            page.getElements().add(label);
            document.getPages().add(page);
            
            // Save the PDF
            document.draw("[PhysicalPath]/MyDocument.pdf" );
        } catch (FileNotFoundException ex) {
            ex.printStackTrace();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
       }
 }